var city_list = require("../../server/_include/city/city.json");
var base_uid_map = Object.create(null);
var city_map = {};

//数据关系树化
city_list.forEach(function(item) {
	city_map[item.region_id] = item;
});

//根据parent_id生成对应的base_id
//base_id >= 1
city_list.forEach(function(item) {
	var base_id = base_uid_map[item.parent_id] = ~~base_uid_map[item.parent_id] + 1;
	city_map[item.region_id].base_id = ("00" + base_id).substr(-2);
});

//把base_id连接起来连城parent_id
//把parent_id转化成完整district_id
//写入数据库
city_list.forEach(function(item) {
	var parent = city_map[item.parent_id];
	if (parent) {
		var parent_id = parent.parent_id;
		if (!parent_id) {
			console.log("ERROR NO PARENT_ID:", parent)
		}
	}
	item.parent_id = (parent_id || "") + item.base_id;
	item.district_code = (item.parent_id + "000000").substr(2, 6);
	console.log(item.region_name, item.district_code);
});